package com.ywjt.platformbusiness.order.activity;

import android.content.Context;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.widget.TextView;

import androidx.fragment.app.Fragment;
import androidx.viewpager2.widget.ViewPager2;

import com.cy.tablayoutniubility.FragPageAdapterVp2;
import com.cy.tablayoutniubility.TabAdapter;
import com.cy.tablayoutniubility.TabLayoutScroll;
import com.cy.tablayoutniubility.TabMediatorVp2;
import com.cy.tablayoutniubility.TabViewHolder;
import com.ywjt.platformbusiness.R;
import com.ywjt.platformbusiness.base.BaseActivity;
import com.ywjt.platformbusiness.order.fragment.OrderFragment;

import java.util.ArrayList;
import java.util.List;


public class ActivityOrderList extends BaseActivity {
    private TabLayoutScroll tab1;

    private ViewPager2 viewpager;
    private int status=0;

    public static void actionStart(Context context) {
        Intent intent = new Intent(context, ActivityOrderList.class);
        context.startActivity(intent);
    }

    @Override
    protected void init(Bundle savedInstanceState) {
        setAndroidNativeLightStatusBar(true);
    }

    @Override
    protected int setLayoutResourceID() {
        return R.layout.activity_myorder;
    }

    @Override
    protected void initView() {
        setTitleText("订单");
        tab1=findViewById(R.id.tab1);
        viewpager=findViewById(R.id.viewpager);
        FragPageAdapterVp2<String> fragmentPageAdapter = new FragPageAdapterVp2<String>(this) {

            @Override
            public Fragment createFragment(String bean, int position) {
                switch (position) {
                    case 0://全部
                        status = -1;
                        break;
                    case 1://待付款
                        status = 0;
                        break;
                    case 2://待发货
                        status = 1;
                        break;
                    case 3://待收货
                        status = 2;
                        break;
                    case 4://完成
                        status=3;
                        break;
                    case 5://退换货
                        status=4;
                        break;
                }
                OrderFragment orderFragment = OrderFragment.newInstance(status);
                return orderFragment;
            }

            @Override
            public void bindDataToTab(TabViewHolder holder, int position, String bean, boolean isSelected) {
                TextView textView = holder.getView(R.id.tv);
                if (isSelected) {
                    textView.setTextColor(0xffFB222A);
                    textView.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
                } else {
                    textView.setTextColor(0xff333333);
                    textView.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
                }
                textView.setText(bean);
            }

            @Override
            public int getTabLayoutID(int position, String bean) {
                return R.layout.tab_item;
            }
        };
        TabAdapter<String> tabAdapter = new TabMediatorVp2<String>(tab1, viewpager).setAdapter(fragmentPageAdapter);
        List<String> list = new ArrayList<>();
        list.add("全部");
        list.add("待付款");
        list.add("待发货");
        list.add("待收货");
        list.add("已完成");
        list.add("售后");
        fragmentPageAdapter.add(list);
        tabAdapter.add(list);

    }


    @Override
    protected void initData() {
        setAndroidNativeLightStatusBar(true);
    }

    @Override
    protected int getTitleBarType() {
        return TITLEBAR_DEFAULT;
    }

}
